<?php
// +----------------------------------------------------------------------
// | Iecms [ Make the most exquisite CMS ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009~2019 http://www.iemoo.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: iemoo <i@iemoo.com>
// +----------------------------------------------------------------------
// | DateTime: 2019/11/19 11:08
// +----------------------------------------------------------------------
namespace app\index\controller;

use app\common\model\Page as PageModel;

use think\facade\Request;
use think\facade\View;


class Page extends Base
{

    public function index()
    {
		//获取栏目名
		$name = Request::param('name');
		
		$page = PageModel::where('name',$name)->where('status',1)->findOrEmpty();
		if ($page->isEmpty()) {
			return $this->error('此内容不可访问');
		}

		$images = $page->files->toArray();

		//更新浏览量
		$page->hits += 1;
		$page->save();

		//获取模板名 
		$template =  'page_default';
		if(!empty($page->getData('template'))){
			$template = $page->getData('template');
		}
		View::assign('info',$page);
		View::assign('images',$images);


		View::assign('title',$page->title . ' - ');
		View::assign('keywords',$page->keywords . ',');
		View::assign('description',$page->description);

		return View::fetch($template);
    }

}
